
package net.atremmedia.gwt.actionjava.examples.basics.samples;

import net.atremmedia.gwt.actionjava.examples.AJExample;
import net.atremmedia.gwt.actionjava.examples.frame.AJExampleOverview;
import actionjava.display.Graphics;
import actionjava.display.Shape;
import actionjava.events.tick.TickEvent;

public class Acceleration extends AJExample
{
	public static final String NAME = "Acceleration";
	public static final String DESCRIPTION = "Description";
	public static final String EXAMPLE_SRC = "https://code.google.com/p/gwt-actionjava/source/browse/trunk/aj-examples/aj-examples-basics/src/main/java/net/atremmedia/gwt/actionjava/examples/basics/samples/Acceleration.java";

	private Shape ball;
	private double vx = 0;
	private double ax = .2;

	public Acceleration(AJExampleOverview base)
	{
		super(NAME, DESCRIPTION, EXAMPLE_SRC, base);
	}

	private void initialize()
	{
		vx = 0;
		ax = .2;
	}

	@Override
	public void run()
	{
		initialize();
		addChild(createBall());
	}

	private Shape createBall()
	{
		ball = new Shape();
		ball.setX(50);
		ball.setY(100);

		Graphics graphs = ball.getGraphics();
		graphs.beginFill(getRandomColor());
		graphs.drawCircle(0, 0, 50);
		graphs.endFill();

		return ball;
	}

	@Override
	public void onRenderTick(TickEvent event)
	{
		vx += ax;
		ball.addX(vx);
	}
}
